﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DesignPatterns.FactoryPatterns
{
    /// <summary>
    /// 简单工厂
    /// 1.抽象一个产品基类
    /// 2.基于产品基类定义各种产品
    /// 3.创建一个工厂类，输入产品名称，根据ifelse或switch等判断返回对应的产品
    /// 当产品少，以后也不容易扩展的时候，适合用简单工厂
    /// 否则以后经常性扩展产品，会导致简单工厂类不停地修改
    /// </summary>
    class SimpleFactoryClient
    {
        static void Main(string[] args)
        {
            // 客户想点一个西红柿炒蛋        
            Food food1 = FoodSimpleFactory.CreateFood("西红柿炒蛋");
            food1.Print();

            // 客户想点一个土豆肉丝
            Food food2 = FoodSimpleFactory.CreateFood("土豆肉丝");
            food2.Print();

            Console.Read();
        }
    }

    /// <summary>
    /// 简单工厂类, 负责 炒菜
    /// </summary>
    public class FoodSimpleFactory
    {
        public static Food CreateFood(string type)
        {
            Food food = null;
            if (type.Equals("土豆肉丝"))
            {
                food = new ShreddedPorkWithPotatoes();
            }
            else if (type.Equals("西红柿炒蛋"))
            {
                food = new TomatoScrambledEggs();
            }

            return food;
        }
    }
}
